#!/usr/bin/python3

def t():
    num = [1,2,3,4,5,6,7,8,9,10]
    # 分片功能
    print(num[3:6])
    print(num[-3:-1])

    del num[2]
    print(num)

    # 分片赋值
    name = list('Perl')
    name[2:] = list('ar')
    print(name)

    # 分片插入
    n = [1,5]
    n[1:1] = [2,3,4]
    print('slice insert:', n)

    # 列表方法
    n.append(6)
    a = [1,2]
    a.extend(n) # 会修改a
    a.sort()  # 原位排序
    print('extend:', a)

    # 如果不想原位排序，则先拷贝，再排序  
    y = a[:]
    y.sort()
    print('copy first, then sort:', y)

def t_for_loop():
    for i in list:
        print("i：%s   v：%s" % (list.index(i) + 1, i))

    for i in range(len(list)):
        print("i：%s   v：%s" % (i + 1, list[i]))

    for i, val in enumerate(list):
        print("i：%s   v：%s" % (i + 1, val))

    for i, val in enumerate(list, 2):
        print("i：%s   v：%s" % (i + 1, val))

if __name__ == '__main__':
    t()